package com.pai4j.message.provider;

import com.pai4j.message.core.provider.AbstractResourceProvider;
import com.pai4j.message.model.ResourceInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * 视频资源提供者（示例实现）
 * 提供视频资源信息
 * 
 * <p>当前为示例实现，返回模拟数据。
 * 实际使用时需要注入VideoClient并调用实际的视频服务API。</p>
 *
 * @author PAI4J Team
 * @date 2025-11-01
 */
@Slf4j
@Component
public class VideoResourceProvider extends AbstractResourceProvider {

    // TODO: 注入视频服务Client
    // @Autowired
    // private VideoClient videoClient;

    @Override
    public String getResourceType() {
        return "VIDEO";
    }

    @Override
    protected ResourceInfo doGetResourceInfo(String resourceId) {
        if (StringUtils.isBlank(resourceId)) {
            return null;
        }

        try {
            // TODO: 调用实际的视频服务获取视频信息
            // PAIResponseBean<VideoDetailVO> response = videoClient.getVideoDetail(videoId);
            
            log.debug("获取视频资源信息: videoId={}", resourceId);
            
            // 实际项目中应该这样实现：
            /*
            Long videoId = Long.parseLong(resourceId);
            PAIResponseBean<VideoDetailVO> response = videoClient.getVideoDetail(videoId);
            
            if (!PAIResponseBeanUtil.isOk(response) || response.getData() == null) {
                log.warn("获取视频信息失败: videoId={}", videoId);
                return null;
            }

            VideoDetailVO video = response.getData();
            
            return ResourceInfo.builder()
                    .resourceId(resourceId)
                    .resourceType("VIDEO")
                    .title(video.getTitle())
                    .ownerId(video.getAuthorId())
                    .authorName(video.getAuthorName())
                    .coverImage(video.getCoverImage())
                    .summary(video.getDescription())
                    .jumpUrl("/video/detail/" + resourceId)
                    .status(video.getStatus())
                    .addExtInfo("duration", video.getDuration())
                    .addExtInfo("playCount", video.getPlayCount())
                    .addExtInfo("likeCount", video.getLikeCount())
                    .addExtInfo("categoryId", video.getCategoryId())
                    .addExtInfo("videoUrl", video.getVideoUrl())
                    .build();
            */

            // 临时返回基本信息（待集成实际服务时替换）
            return ResourceInfo.builder()
                    .resourceId(resourceId)
                    .resourceType("VIDEO")
                    .title("视频-" + resourceId)
                    .ownerId("author-" + resourceId)
                    .authorName("作者名称")
                    .jumpUrl("/video/detail/" + resourceId)
                    .status(null)
                    .build();

        } catch (Exception e) {
            log.error("获取视频资源信息异常: resourceId={}, error={}", resourceId, e.getMessage(), e);
            return null;
        }
    }

    @Override
    public int getPriority() {
        return 8; // 中高优先级
    }
}

